package com.yc.sakuralxm.uestcscanning.tools

import android.os.Environment

import java.io.File
import java.io.FileWriter

/**
 * @author YKX
 * @description
 */
object FilePathUtil {
    /**
     * 数据库根目录
     *
     * @return
     */
    val dbDir: String
        get() {
            val builder = StringBuilder()
            builder.append(rootDir).append("data").append(File.separator)
            return builder.toString()
        }

    /**
     * 聊天语音根目录
     *
     * @return
     */
    val chatAudioDir: String
        get() {
            val builder = StringBuilder()
            builder.append(rootDir).append("chat").append(File.separator)
                    .append("voice").append(File.separator)
            return builder.toString()
        }

    /**
     * 聊天图片目录
     *
     * @return
     */
    val chatImageDir: String
        get() {
            val builder = StringBuilder()
            builder.append(rootDir).append("chat").append(File.separator)
                    .append("image").append(File.separator)
            return builder.toString()
        }

    /**
     * 软件文件存储和缓存根目录
     *
     * @return
     */
    val rootDir: String
        get() {
            val builder = StringBuilder()
            builder.append(Environment.getExternalStorageDirectory())
            builder.append(File.separator).append("doctorDic")
                    .append(File.separator)
            return builder.toString()
        }

    val apkTempDir: String
        get() {
            val builder = StringBuilder()
            builder.append(rootDir).append("apk").append(File.separator)
            return builder.toString()
        }

    val isExitsSdcard: Boolean
        get() = Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED

    val sdCardPath: String
        get() = if (isExitsSdcard) {
            Environment.getExternalStorageDirectory().toString() + "/"
        } else "/mnt/sdcard"

    fun stringTxt(str: String) {
        try {
            val fw = FileWriter(sdCardPath + "/md5.txt")//SD卡中的路径
            fw.flush()
            fw.write(str)
            fw.close()
            L.e("文件写入")
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }
}
